<!DOCTYPE html>
<html>
{include file="public/head"}

<body>
    {include file="public/nav"} {include file="public/nav-2"}
    <!-- 分割线 -->
    <div class="layui-container fly-marginTop">
        <div class="fly-panel fly-panel-user" pad20="">
            <div class="layui-tab layui-tab-brief" lay-filter="user">
                <p>您的邮箱将在注册后激活,请填写如下信息完成注册</p>
                <div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 20px 0;">
                    <div class="layui-tab-item layui-show">
                        <div class="layui-form layui-form-pane">
                            <form method="post" id="myform" name="myform" action="{:url('user/submitregister')}">
                                <input name="key" value="{$key}" class="layui-hide" />
                                <div class="layui-form-item">
                                    <label for="L_email1" class="layui-form-label">登录邮箱</label>
                                    <div class="layui-input-inline">
                                        <input type="text" id="email" value="{$email}" name="email" class="layui-input layui-disabled"  readonly>
                                    </div>
                                    <div class="layui-form-mid layui-word-aux">将用来找回密码</div>
                                </div>
                                <div class="layui-form-item">
                                    <label for="L_email3" class="layui-form-label">用户名</label>
                                    <div class="layui-input-inline">
                                        <input type="text" id="username" name="username" required="" lay-verify="username" autocomplete="off" class="layui-input" placeholder="请输入用户名">
                                    </div>
                                    <div class="layui-form-mid layui-word-aux">由下划线、数字、字母组成</div>
                                </div>
                                <div class="layui-form-item">
                                    <label for="L_email5" class="layui-form-label">密码</label>
                                    <div class="layui-input-inline">
                                        <input type="password" id="password1" name="password1" required="" lay-verify="pass" autocomplete="off" class="layui-input" placeholder="请输入密码">
                                    </div>
                                    <div class="layui-form-mid layui-word-aux">密码长度为6~18位</div>
                                </div>
                                <div class="layui-form-item">
                                    <label for="L_email7" class="layui-form-label">确认密码</label>
                                    <div class="layui-input-inline">
                                        <input type="password" id="password2" name="password2" required="" lay-verify="pass" autocomplete="off" placeholder="请再次输入密码" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <!-- <button class="layui-btn" onclick="submit_var()">提交</button> -->
                                    <div class="layui-form-item">
                                        <button class="layui-btn" lay-filter="register" lay-submit>立即注册</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- 分割线 -->
    {include file="public/foot"}
</body>
<script>
layui.use(['form', 'jquery'], function() {
    var form = layui.form;
    var $ = layui.jquery;
    form.on('submit(register)', function(data) {
        // console.log(data.field);
        if (!submit_var()) return false;
        $.ajax({
            url: "{:url('user/judgeuserid')}",
            data: data.field,
            type: 'post',
            dataType: 'JSON',
            success: function(res) {
                // console.log("res=" + res.result);
                if (res.result == true) {
                    // layer.msg('pc注册成功!');
                    window.location.href = "{:url('user/submitregister')}";
                } else
                    layer.msg(res.msg);
            },
            error: function() {
                layer.msg('进入后台失败');
            }
        });
        return false;
    });
});


function submit_var() {
    var username = document.forms["myform"]["username"].value;
    var reg = new RegExp(/^\w+$/);
    if (!reg.test(username)) {
        layui.use('layer', function() {
            var layer = layui.layer;
            layer.msg('用户名由下划线、数字、字母组成');
        });
        return false;
    }
    if(username.length>40) {
        layer.msg('用户名长度应小于40');
        return false;
    }
    var passwd1 = document.forms["myform"]["password1"].value;
    var passwd2 = document.forms["myform"]["password2"].value;
    if (passwd1 != passwd2) {
        layui.use('layer', function() {
            var layer = layui.layer;
            layer.msg('两次密码不一致~');
        });
        return false;
    }
    if(passwd1.length<6||passwd1.length>18) {
        layui.use('layer', function() {
            var layer = layui.layer;
            layer.msg('密码长度为6~18位！');
        });
        return false;;
    }
    return true;
}
</script>>

</html>